using RazorEngine.Text;
using System;

namespace TestMonkey.Models
{
	/// <summary>
	/// This class allows us to bypass encoding in RazorEngine templates.
	/// </summary>
	public class CodeString : IEncodedString
	{
		readonly string m_Value;

		/// <summary>
		/// Initializes a new instance of the <see cref="CodeString"/> class.
		/// </summary>
		/// <param name="value">The value.</param>
		public CodeString(string value)
		{
			m_Value = value;
		}

		/// <summary>
		/// Returns a <see cref="System.String" /> that represents this instance.
		/// </summary>
		/// <returns>
		/// A <see cref="System.String" /> that represents this instance.
		/// </returns>
		public override string ToString()
		{
			return m_Value;
		}

		/// <summary>
		/// Gets the encoded string.
		/// </summary>
		/// <returns>
		/// The encoded string.
		/// </returns>
		public string ToEncodedString()
		{
			return m_Value;
		}

		/// <summary>
		/// Performs an implicit conversion from <see cref="System.String"/> to <see cref="CodeString"/>.
		/// </summary>
		/// <param name="value">The value.</param>
		/// <returns>
		/// The result of the conversion.
		/// </returns>
		public static implicit operator CodeString(string value)
		{
			return new CodeString(value);
		}

		/// <summary>
		/// Performs an implicit conversion from <see cref="CodeString"/> to <see cref="String"/>.
		/// </summary>
		/// <param name="value">The value.</param>
		/// <returns>
		/// The result of the conversion.
		/// </returns>
		public static implicit operator String(CodeString value)
		{
			if (value == null) return null; else return value.ToString();
		}
	}

}
